/*     */ package com.wzh.utils;
/*     */ 
/*     */ import com.wzh.constant.CommonConstant;
/*     */ import java.io.FileInputStream;
/*     */ import java.io.FileOutputStream;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.net.URL;
/*     */ import java.util.Enumeration;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import java.util.Properties;
/*     */ 
/*     */ public class PropertiesUtil
/*     */ {
/*  21 */   private Properties property = new Properties();
/*     */   private String filepath;
/*     */   private String filename;
/*     */ 
/*     */   public PropertiesUtil(String filename)
/*     */   {
/*  30 */     String path = Thread.currentThread().getContextClassLoader().getResource(CommonConstant.DELIMITER).getPath();
/*  31 */     this.filename = filename;
/*  32 */     this.filepath = (path + filename);
/*     */     try {
/*  34 */       InputStream is = new FileInputStream(this.filepath);
/*  35 */       this.property.load(is);
/*     */     }
/*     */     catch (IOException e) {
/*  38 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */ 
/*     */   public String getProperty(String key)
/*     */   {
/*  44 */     return this.property.getProperty(key);
/*     */   }
/*     */ 
/*     */   public void setProperty(String key, String value) {
/*  48 */     this.property.setProperty(key, value);
/*     */     try
/*     */     {
/*  51 */       FileOutputStream fos = new FileOutputStream(this.filepath);
/*  52 */       this.property.store(fos, "update" + System.currentTimeMillis());
/*  53 */       fos.flush();
/*  54 */       fos.close();
/*     */ 
/*  56 */       clearCache();
/*     */     } catch (IOException e) {
/*  58 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */ 
/*     */   public void setProperties(Map<String, String> map)
/*     */   {
/*  64 */     if ((map == null) || (map.size() == 0)) {
/*  65 */       return;
/*     */     }
/*     */ 
/*  68 */     for (Map.Entry entry : map.entrySet()) {
/*  69 */       this.property.setProperty((String)entry.getKey(), (String)entry.getValue());
/*     */     }
/*     */     try
/*     */     {
/*  73 */       FileOutputStream fos = new FileOutputStream(this.filepath);
/*  74 */       this.property.store(fos, "update" + System.currentTimeMillis());
/*  75 */       fos.flush();
/*  76 */       fos.close();
/*     */ 
/*  78 */       clearCache();
/*     */     } catch (IOException e) {
/*  80 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */ 
/*     */   public Map<String, String> getAllProperties()
/*     */   {
/*  86 */     Map map = new HashMap();
/*     */ 
/*  88 */     Enumeration en = this.property.propertyNames();
/*  89 */     while (en.hasMoreElements()) {
/*  90 */       String key = (String)en.nextElement();
/*  91 */       map.put(key, this.property.getProperty(key));
/*     */     }
/*  93 */     return map;
/*     */   }
/*     */ 
/*     */   private void clearCache()
/*     */   {
/*  99 */     String path = Thread.currentThread().getContextClassLoader().getResource("/").getPath();
/*     */ 
/* 101 */     this.filepath = (path + this.filename);
/*     */     try {
/* 103 */       InputStream is = new FileInputStream(this.filepath);
/* 104 */       this.property.load(is);
/*     */     }
/*     */     catch (IOException e) {
/* 107 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\work\apache-tomcat-7.0.55\webapps\ROOT\WEB-INF\classes\
 * Qualified Name:     com.wzh.utils.PropertiesUtil
 * JD-Core Version:    0.6.1
 */